#ifndef __DS1307_H
#define	__DS1307_H
//
//外部实时钟芯片DS1307程序
//
#include "stm32f10x.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

//#define RTC_PCF8563 1

#ifndef RTC_PCF8563
	#define RTC_DS1337		1
	#define RTC_ID			0xD0
#else
	#define RTC_ID			0xA2
#endif

//ds1337的控制脚定义
#define DS1307_SCL_H()		GPIO_SetBits(GPIOB, GPIO_Pin_8)
#define DS1307_SCL_L()		GPIO_ResetBits(GPIOB, GPIO_Pin_8)
#define DS1307_SDA_H()		GPIO_SetBits(GPIOB, GPIO_Pin_9)
#define DS1307_SDA_L()		GPIO_ResetBits(GPIOB, GPIO_Pin_9)
#define DS1307_SDA_Read()	GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9)

//时钟
typedef struct
{
	uint8_t tm_sec;
	uint8_t tm_min;
	uint8_t tm_hour;
	uint8_t tm_day;
	uint8_t tm_mon;
	uint8_t tm_week;
	uint16_t tm_year;
}CurrentDateTimes;

extern CurrentDateTimes  device_time;
extern uint32_t m_rtc_timer_sec;
extern uint8_t	nowtime[7];			//DS1307的寄存器时间

void ReadTime_Now(void);
uint8_t ds1307_Init(void);
void ds1307_SetTime(uint8_t *buf);
void ds1307_GetTime(uint8_t *buf);

#endif //__DS1307_H
